package com.lx.lxsql.execute;    //说明: 解析并执行脚本

import com.lx.lxsql.entity.StatementInformation;
import com.lx.lxsql.util.ScanPackage;

import java.util.*;

/**
 * { ylx } 2021/9/12 21:16
 */
public abstract class Execute {
    protected static final List<Execute> EXECUTES = new ArrayList<>();
    public static List<Execute> getEXECUTES() throws Exception {
        if (EXECUTES.size() == 0){
            synchronized (Execute.class){
                if (EXECUTES.size() == 0){
                    Set<Class<?>> scan = ScanPackage.scan(new HashSet<>(), (cls) -> {
                        return Execute.class.isAssignableFrom(cls);
                    }, Execute.class.getPackage().getName());
                    for (Class<?> c : scan) {
                        EXECUTES.add((Execute) c.newInstance());
                    }
                }
            }
        }
        return EXECUTES;
    }

    public abstract boolean matching(LinkedList<StatementInformation> ls);
    public abstract <T>T exec(ExecuteUtil util);

}
